<template>
	<view class="wrap">
		
		<CouponCellNew
			:couponId="dataDetail.couponId"
			:discountAmount="dataDetail.money"
			:rangInfo="dataDetail.preferentialInfo"
			:activityType="dataDetail.couponName"
			:durationDate="dataDetail.useTime"
			:couponType="dataDetail.useTypeName"
			:storeRang = "dataDetail.applicableUnit"
			:isReceive.sync="dataDetail.tag"
			:useNotice="dataDetail.serviceItems"
			:applicableUnitType="dataDetail.stores"
			@getCoupon="getCoupon"
			></CouponCellNew>
		
		
		
	</view>
</template>

<script>
	import CouponCellNew from '../../components/coupon/coupon-cell-new.vue'
	
	import {
		apiMyCouponInfo,
		turnCoupon
	} from '../../common/api.js'
	export default {
		components: {
			CouponCellNew,
		},

		data() {
			return {
				counponInfo: {},
				memberId: '',
				showGive: false,
				turnMemberNo: '',
				dataDetail:{}
			}
		},

		onLoad(op) {
			this.dataDetail = op;
			console.log('接到的参数', op);
			
			this.memberId = op.memberId;
			if (op.type == 1) { //转赠进来
				console.log('收到的deptId=>', op.deptId);
				
				getApp().globalData.tempDeptId = op.deptId;
				if(!uni.$u.test.isEmpty(op.deptId)){
					this.$store.commit('user/saveSourceType', 4);
					this.$store.commit('user/savedeptId', op.deptId);
				}
				
				getApp().globalData.tempCustomerId = op.customerId;
				if(!uni.$u.test.isEmpty(op.customerId)){
					this.$store.commit('user/saveCustomerId', op.customerId);
				}
			
			
				console.log(this.memberId);
				this.turnMemberNo = op.turnMemberNo;
				console.log(this.turnMemberNo);
				this.showGive = true;
				this.$store.dispatch('user/MmvLogin').then(data => {
					console.log('成功了');
					this.getData();
				}).catch(err => {
					console.log('失败了');
					uni.showToast({
						title: '授权失败',
						icon: 'error'
					});
				})
			} else { //立即使用进来
				this.getData();
			}
		},
		methods: {
			getData() {
				console.log(this.memberId);
				apiMyCouponInfo(
					this.memberId
				).then(res => {
					this.counponInfo = res;
				})
			},

			givingCoupon() {
				turnCoupon({
					memberNo: this.$store.state.user.userInfo.customerId,
					memberId: this.memberId,
					turnMemberNo: this.turnMemberNo
				}).then(res => {
					uni.showToast({
						title: '领取成功',
						icon: 'success'
					})
					uni.redirectTo({
						url: './mine-couponList'
					})
				})
			},

			goStore() {
				uni.navigateTo({
					url: './coupon-store?businessId=' + this.counponInfo.businessId
				})
			},
			goCar() {
				uni.navigateTo({
					url: './coupon-car?businessId=' + this.counponInfo.businessId
				})
			}
		}

	}
</script>

<style lang="scss" scoped>
	.wrap {
	}

</style>
